package com.sto.stoapp.activity.scanner;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.util.UnifiedStaticType;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoScanTwentyFourHoursActivity extends StoHomeActivity {

    // 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.received_piece,
            R.string.send_piece, R.string.to_piece, R.string.package_send_piece };
//    private ListView scanMainList;

    private ListView hoursList;

    private SoleAdapter soleAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sto_sales_received_piece);
        this.setTitleBottom(R.string.h_received_piece,
                HomeBroadAction.SCANNER_MAN_BROAD);
        initWidget();

    }

    private void initWidget() {
        hoursList = (ListView) findViewById(R.id.receivedFunc_list);
        soleAdapter = new SoleAdapter(this, getResourceList());
        hoursList.setAdapter(soleAdapter);
        hoursList.setOnItemClickListener(new StoOnItemClickListener(this) {

            @Override
            public void KcOnItemClickListener(AdapterView<?> parent, View view,
                    int position, long id) {
                view.setSelected(true);
                TextView title = (TextView) view.findViewById(R.id.res_test);
                clickItemEvent(title.getText().toString());

            }
        });

    }

    private void clickItemEvent(String title) {
        // 网点-收件
        if (title.equals(getText(R.string.received_piece))) {
            Intent intent = new Intent(this, StoScanReceiveActivity.class);
            //			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 网点-发件
        else if (title.equals(getText(R.string.send_piece))) {
            Intent intent = new Intent(this, StoScanSendPieceActivity.class);
            //			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 网点-到件
        else if (title.equals(getText(R.string.to_piece))) {
            Intent intent = new Intent(this, StoScanToPieceActivity.class);
            //			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 网点-装袋&发件
        else if (title.equals(getText(R.string.package_send_piece))) {
            Intent intent = new Intent(this,
                    StoScanBagAndSendPieceActivity.class);
            //			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("busiType", HomeBroadAction.SCANNER_MAN_BROAD);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
    }

    private List<FunctionEntity> getResourceList() {
        List<String> resList = new ArrayList<String>();
        resList.add(getText(R.string.received_piece).toString());
        resList.add(getText(R.string.send_piece).toString());
        resList.add(getText(R.string.to_piece).toString());
        resList.add(getText(R.string.package_send_piece).toString());

        List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
        for (String res : resList) {
            FunctionEntity entity = new FunctionEntity();
            entity.setTitle(res);
            functionList.add(entity);
        }
        return functionList;
    }





}
